package com.byxm.wlgw.query;

import java.util.List;

import com.byxm.wlgw.bean.GwcxxBean;
/**
 * 订单商品信息service
 * @author Administrator
 *
 */
public class DdspxxQuery {
	
	
	public String findDdspxx(String ddxxid){
		StringBuffer sql=new StringBuffer();
		sql.append("select t1.ddspxxid,t1.ddxxid,t1.spxxid,t1.spsl,");
		sql.append("t2.spyj,t2.spsj,t2.sphh,");
		sql.append("t3.spppm,");
		sql.append("t4.splbm,");
		sql.append("t5.spxhnr");
		sql.append("  from ddspxx t1 ");
		sql.append("  left join spxx t2 on t1.spxxid=t2.spxxid ");
		sql.append("  left join sppp t3 on t2.ppid=t3.spppid ");
		sql.append("  left join splb_f t4 on t2.splbfid=t4.splbfid");
		sql.append("  left join spxh t5 on t1.spxhid=t5.xhid ");
		sql.append(" where t1.ddxxid='").append(ddxxid).append("'");
		
		return sql.toString();
	}
	
	
	
	
	/**
	 * 插入订单商品信息sql
	 * @param ddxxid
	 * @param lstGwcxx
	 * @return
	 */
	public String getInsertDdxpxxSql(String ddxxid,List<GwcxxBean> lstGwcxx){
		StringBuffer sql = new StringBuffer();
		sql.append("INSERT INTO ddspxx(ddxxid,spxxid,spsl,spxhid,sptp,spmc) ");
		if(lstGwcxx.size()==1){
			sql.append(" SELECT '").append(ddxxid).append("',");//订单信息ID ddxxid
			sql.append(lstGwcxx.get(0).getSpxxid()).append(",");//spxxid
			sql.append(lstGwcxx.get(0).getSpsl()).append(",");//spsl
			sql.append(lstGwcxx.get(0).getSpxhid()).append(",");//spxhid
			sql.append("'").append(lstGwcxx.get(0).getSptp()).append("',");//sptp商品图片
			sql.append("'").append(lstGwcxx.get(0).getSpbt()).append("'");//商品名称
		}
		if(lstGwcxx.size()>1){
			for(int i=0;i<lstGwcxx.size()-1;i++){
				sql.append(" SELECT '").append(ddxxid).append("',");//订单信息ID ddxxid
				sql.append(lstGwcxx.get(i).getSpxxid()).append(",");//spxxid
				sql.append(lstGwcxx.get(i).getSpsl()).append(",");//spsl
				sql.append(lstGwcxx.get(i).getSpxhid()).append(",");//spxhid
				sql.append("'").append(lstGwcxx.get(i).getSptp()).append("',");//sptp商品图片
				sql.append("'").append(lstGwcxx.get(i).getSpbt()).append("'");//商品名称
				sql.append(" UNION ALL ");
			}
			sql.append(" SELECT '").append(ddxxid).append("',");//订单信息ID ddxxid
			sql.append(lstGwcxx.get(lstGwcxx.size()-1).getSpxxid()).append(",");//spxxid
			sql.append(lstGwcxx.get(lstGwcxx.size()-1).getSpsl()).append(",");//spsl
			sql.append(lstGwcxx.get(lstGwcxx.size()-1).getSpxhid()).append(",");//spxhid
			sql.append("'").append(lstGwcxx.get(lstGwcxx.size()-1).getSptp()).append("',");//sptp商品图片
			sql.append("'").append(lstGwcxx.get(lstGwcxx.size()-1).getSpbt()).append("'");//商品名称
		}
		return sql.toString();
	}
	/**
	 * 查询订单商品信息
	 * @return
	 */
	public String findDdspxxSql(){
		StringBuffer sql=new StringBuffer();
		sql.append("select dd.sptp,dd.spmc,sp.spsj,dx.shrxm,dx.jyzt,dx.ddxxid from ddspxx as dd,(select * from spxx) as sp,(select * from ddxx where yhxxid=?) dx where dd.spxxid=sp.spxxid and dd.ddxxid=dx.ddxxid");
		return sql.toString();
	}
	
	/*******私有方法区*******/
}
